package com.luocj.muke.demo.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.luocj.muke.demo.R;
import com.luocj.muke.demo.utils.GridItemDecoration;
import com.luocj.muke.demo.utils.LinearItemDecoration;

import java.util.ArrayList;

public class LinearDiverActivity extends AppCompatActivity {

    private RecyclerView recyclerview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_linear_diver);

        initView();

    }

    private void initView() {
        recyclerview = findViewById(R.id.recyclerview1);

        LinearItemDecoration divider = new LinearItemDecoration.Builder(LinearDiverActivity.this)
                .setHorizontalSpan(R.dimen.common_vew_column_padding)
                .setVerticalSpan(R.dimen.common_vew_raw_padding)
                .setColorResource(R.color.orange)
                .setShowLastLine(false)
                .build();
        recyclerview.addItemDecoration(divider);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerview.setLayoutManager(linearLayoutManager);
        LinearDiverAdapter adapter = new LinearDiverAdapter(R.layout.item_diver, getData());
        recyclerview.setAdapter(adapter);
    }

    private ArrayList<String> getData() {
        ArrayList<String> strings = new ArrayList<>();

        for (int i = 0; i < 30; i++) {
            strings.add("item :" + i);
        }
        return strings;
    }

    private class LinearDiverAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
        public LinearDiverAdapter(int layoutId, ArrayList<String> data) {
            super(layoutId, data);
        }

        @Override
        protected void convert(BaseViewHolder holder, String item) {
            holder.setText(R.id.tv_content, item);
        }
    }
}
